import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/checkpoint/app_bar.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/checkpoint/checkpoint_prepare_game_center_add.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/checkpoint/checkpoint_prepare_game_footer.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/checkpoint/checkpoint_prepare_game_top_head.dart';
import 'package:flutter_eve_plugin/components/ye_xiu/checkpoint/checkpoint_prepare_game_top_name.dart';
import 'package:flutter_eve_plugin/constants/font_family.dart';
import 'package:flutter_eve_plugin/constants/font_weight.dart';
import 'package:flutter_eve_plugin/constants/hero_tag.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/checkpoint/user_card.dart';
import 'package:flutter_eve_plugin/pages/ye_xiu/checkpoint/actions.dart';
import 'package:flutter_eve_plugin/store/main.dart';
import 'package:flutter_eve_plugin/store_vm/app_vm.dart';
import 'package:flutter_eve_plugin/utils/image_util.dart';
import 'package:flutter_eve_plugin/utils/screen_util.dart';
import 'package:flutter_redux/flutter_redux.dart';

class CheckpointPrepareGamePage extends StatefulWidget {
  final String title;
  CheckpointPrepareGamePage({Key key, this.title}) : super(key: key);

  _CheckpointPrepareGamePageState createState() =>
      _CheckpointPrepareGamePageState();
}

class _CheckpointPrepareGamePageState extends State<CheckpointPrepareGamePage> {
  @override
  Widget build(BuildContext context) {
    return StoreConnector<AppState, AppStateViewModel>(onInit: (store) {
      store.dispatch(userCard(1, context));

      ///恢复默认选择
      updateSelectKey(store, 0);

      ///清空
      pushSelectMap(store, {0: null, 1: null, 2: null, 3: null});
    }, converter: (store) {
      return AppStateViewModel(state: store.state);
    }, builder: (context, vm) {
      var stageInfo = vm.state.yeXiuState.checkpointState.checkpointStageInfo;
      var userCard = vm.state.yeXiuState.checkpointState.userCard;
      CardList jmxInfo;
      List<CardList> showList = [];
      userCard?.cards?.forEach((child) {
        if (child?.card?.name == '君莫笑') {
          jmxInfo = child;
        } else {
          showList.add(child);
        }
      });
      return Container(
        decoration: BoxDecoration(
            image: DecorationImage(
                image: AssetImage(
                    imageUtilYeXiu('checkpoint/icon_checkpoint_bg@3x')),
                fit: BoxFit.fitWidth,
                alignment: Alignment.topCenter)),
        child: SafeArea(
          child: Scaffold(
            backgroundColor: Colors.transparent,
            appBar: buildBackAppBar(),
            body: Stack(
              overflow: Overflow.visible,
              children: <Widget>[
                Positioned(
                  top: setRatio(-35),
                  right: setRatio(14),
                  child: Hero(
                    tag: HeroTag.GAME_BOSS_NAME,
                    child: Text(
                      stageInfo?.stageBasics?.configInfo?.bossname ?? '',
                      style: TextStyle(
                          shadows: [
                            BoxShadow(
                                color: Color(0x80000000),
                                offset: Offset(0, setRatio(2)),
                                blurRadius: setRatio(2))
                          ],
                          fontStyle: FontStyle.italic,
                          color: Color(0xFFFFFFFF),
                          fontFamily: FontFamily.PMZD,
                          fontSize: setTextSp(30)),
                    ),
                  ),
                ),
                Positioned(
                  top: setRatio(-5),
                  right: setRatio(14),
                  child: Text(
                    '选择你要出战的伙伴',
                    style: TextStyle(
                        fontStyle: FontStyle.italic,
                        color: Color(0xFFFFFFFF),
                        fontFamily: FontFamily.PINGFANG,
                        fontWeight: FontWeightCustom.PF_Medium,
                        fontSize: setTextSp(14)),
                  ),
                ),
                Positioned(
                  top: 0,
                  child: SingleChildScrollView(
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: <Widget>[
                        CheckpointPrepareGameTopHeadWidget(info: jmxInfo),
                        CheckpointPrepareGameTopNameWidget(info: jmxInfo),
                        CheckpointPrepareGameCenterAddWidget(data: showList),
                        CheckpointPrepareGameFooterWidget(data: showList, info: jmxInfo),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      );
    });
  }
}
